package com.qf.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import com.qf.feign.SearchFeign;
import com.qf.pojo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lixu
 */
@Service
public class CacheServiceImpl {

    @Autowired
    private SearchFeign searchFeign;

    /**
     * 远程 调用 查询
     * @param id
     * @return
     */
    @CacheResult
    @HystrixCommand(commandKey = "findById")
    public Customer findById(@CacheKey Integer id) {
        return searchFeign.findById(id);
    }

    /**
     * 清除
     * @param id
     */
    @HystrixCommand
    @CacheRemove(commandKey = "findById")
    public void clearFindById(@CacheKey Integer id) {

        System.out.println("====findById的缓存清除了===");
    }
}
